/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lidroid.xutils_sample.slice;

import com.lidroid.xutils_sample.ResourceTable;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.components.TextField;
import ohos.agp.window.dialog.CommonDialog;
import ohos.agp.window.dialog.IDialog;

import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_CONTENT;

public class ViewUtilsPageSlice extends AbilitySlice {
    @ViewInject(id=ResourceTable.Id_button, click="btnClick")
    Button button;

    @ViewInject(id=ResourceTable.Id_textView)
    Text textView;

    public void btnClick(Component component) {
        ViewUtils.injectComponent(component);

        final int textSize = 50, left = 100, top = 10, right = 10, bottom = 70, width = 1000;
        final TextField editText = new TextField(this);
        // 输入框
        editText.setText("大家好");
        editText.setHint("请输入要修改的文字");
        editText.setTextSize(textSize);
        editText.setPadding(left, top, right, bottom);

        new CommonDialog(getContext())
                .setTitleText("请输入文字：")
                .setContentCustomComponent(editText)
                .setButton(1, "ok", new IDialog.ClickedListener(){
                    @Override
                    public void onClick(IDialog iDialog, int i) {
                        String text=editText.getText().toString();
                        textView.setText(text);
                        iDialog.destroy();
                    }
                })
                .setSize(width,MATCH_CONTENT)
                .show();

    }

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_view_utils_page);
            ViewUtils.inject(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
